home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / HandHeldPCPro30 / sdk.exe / Jupiter SDK / data1.cab / MFC_Samples / wcedbtst / wcedbvw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  3.2 KB  |  128 lines

  1. // WCE_DatabaseView.cpp : implementation of the CWCEDBView class
  2. //
  3.  
  4. #include "stdafx.h"
  5.  
  6. #include "wcedbtst.h"
  7. #include "wcedbdoc.h"
  8. #include "wcedbvw.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CWCEDBView
  18.  
  19. IMPLEMENT_DYNCREATE(CWCEDBView, CScrollView)
  20.  
  21. BEGIN_MESSAGE_MAP(CWCEDBView, CScrollView)
  22.     //{{AFX_MSG_MAP(CWCEDBView)
  23.         // NOTE - the ClassWizard will add and remove mapping macros here.
  24.         //    DO NOT EDIT what you see in these blocks of generated code!
  25.         ON_WM_KEYDOWN()
  26.     //}}AFX_MSG_MAP
  27. END_MESSAGE_MAP()
  28.  
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CWCEDBView construction/destruction
  31.  
  32. CWCEDBView::CWCEDBView()
  33. {
  34. }
  35.  
  36. CWCEDBView::~CWCEDBView()
  37. {
  38. }
  39.  
  40. BOOL CWCEDBView::PreCreateWindow(CREATESTRUCT& cs)
  41. {
  42.     return CScrollView::PreCreateWindow(cs);
  43. }
  44.  
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CWCEDBView drawing
  47.  
  48. void CWCEDBView::OnDraw(CDC* pDC)
  49. {
  50.     CWCEDBDoc* pDoc = GetDocument();
  51.     ASSERT_VALID(pDoc);
  52.  
  53.     TEXTMETRIC tm;
  54.     pDC->GetTextMetrics(&tm);
  55.  
  56.     CRect wndRect;
  57.     GetClientRect(&wndRect);
  58.  
  59.     // Workaround for VIEWSCRL.CPP omission of an erase in the ScrollBy() ScrollWindowEX call.
  60.     pDC->FillSolidRect(wndRect,pDC->GetBkColor());
  61.  
  62.     // Workaround for lack of origins in WCE
  63.     // Also, note that SetScrollSizes should use the MM_TEXT map mode
  64.     int nOrgX = -GetScrollPosition().x;
  65.     int nOrgY = -GetScrollPosition().y;
  66.  
  67.     for(int n=0; n < pDoc->Output.GetSize(); n++)
  68.     {
  69.         CClientDC clientDC(this);
  70.         CRect textRect(nOrgX, n*tm.tmHeight + nOrgY, wndRect.Width(), (n+1)*tm.tmHeight + nOrgY);
  71.         clientDC.DrawText(pDoc->Output[n],pDoc->Output[n].GetLength(),textRect,DT_LEFT|DT_TOP);
  72.     }
  73. }
  74.  
  75. /////////////////////////////////////////////////////////////////////////////
  76. // CWCEDBView diagnostics
  77.  
  78. #ifdef _DEBUG
  79. void CWCEDBView::AssertValid() const
  80. {
  81.     CScrollView::AssertValid();
  82. }
  83.  
  84. void CWCEDBView::Dump(CDumpContext& dc) const
  85. {
  86.     CScrollView::Dump(dc);
  87. }
  88.  
  89. CWCEDBDoc* CWCEDBView::GetDocument() // non-debug version is inline
  90. {
  91.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CWCEDBDoc)));
  92.     return (CWCEDBDoc*)m_pDocument;
  93. }
  94. #endif //_DEBUG
  95.  
  96. /////////////////////////////////////////////////////////////////////////////
  97. // CWCEDBView message handlers
  98.  
  99. void CWCEDBView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
  100. {
  101.     CRect rect;
  102.     GetClientRect(&rect);
  103.     
  104.     CSize page(rect.Width()*8/10, rect.Height()*8/10);
  105.  
  106.     SetScrollSizes(MM_TEXT,CSize(1000,1000),page);
  107.     InvalidateRect(NULL);
  108.     UpdateWindow();
  109. }
  110.  
  111. void CWCEDBView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
  112. {
  113.     int nMapMode;
  114.     CSize sizeTotal, sizePage, sizeLine;
  115.     GetDeviceScrollSizes(nMapMode, sizeTotal, sizePage, sizeLine);
  116.  
  117.     if(nChar == VK_UP)
  118.         OnScrollBy(CSize(0,-sizeLine.cy));
  119.     else if(nChar == VK_DOWN)
  120.         OnScrollBy(CSize(0,sizeLine.cy));
  121.     else if(nChar == VK_LEFT)
  122.         OnScrollBy(CSize(-sizeLine.cx,0));
  123.     else if(nChar == VK_RIGHT)
  124.         OnScrollBy(CSize(sizeLine.cx,0));
  125.     else
  126.         CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
  127. }
  128.